package com.sz.mgc.goldrush;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;


public class RadiusDialog extends Dialog {

    private  View mView;
    private  Context mContext;
    private  volatile RadiusDialog singleDialog;

    public RadiusDialog(Context context) {
        this(context, 0, null);
    }

    private RadiusDialog(Context context, int theme, View contentView) {
        super(context, theme == 0 ? R.style.MyDialogStyle : theme);

        mView = contentView;
        mContext = context;
    }

    public  RadiusDialog getInstance(Context context) {
        if (singleDialog == null) {
            synchronized (RadiusDialog.class) {
                if (singleDialog == null) {
                    singleDialog = new RadiusDialog(context);
                }
            }
        }
        return singleDialog;
    }

    public void init(int layoutId) {
        if (mView == null) {
            mView = View.inflate(mContext, layoutId, null);
        }
        this.setContentView(mView);
    }

    public void setWidth(float width, LinearLayout bg) {
        //设置背景是屏幕的0.75
        bg.setLayoutParams(new FrameLayout.LayoutParams((int) (getMobileWidth(mContext) * width), LayoutParams.WRAP_CONTENT));

    }

    public static int getMobileWidth(Context context) {
        DisplayMetrics dm = new DisplayMetrics();
        ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(dm);
        int width = dm.widthPixels;
        // 得到宽度
        return width;
    }
}
